//
//  hNewsDetailController.swift
//  WxToutiao
//
//  Created by YQ05 on 2018/4/12.
//  Copyright © 2018年 yons. All rights reserved.
//

import UIKit
import WebKit

class hNewsDetailController: UIViewController {
    var webView :WKWebView!
    var post: NewsData2!
    
    
    func loadHTML(){
        let frame = CGRect(x: 0, y: 44, width: view.frame.width, height: view.frame.height - 44 - 20)
        webView = WKWebView(frame: frame)
        //view.addSubview(webView)
        view.insertSubview(webView, at: 0)
        
        //webView.load(URLRequest(url: url))
        
        //<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        var header = """
        <html>
        <head>
        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
        """
        
        //<style type="text/css">
        //        body {background-color: red}
        //        p {margin-left: 20px}
        //        </style>
        
        header += """
        <style>
        img { width: 100% } body { font-size: 100%; }
        </style>
        """
        
        //<script src="http://localhost:8888/wordpress/wp-content/uploads/2017/06/scroll.js"></script>
        //header += "<script src=\"http://localhost:8888/wordpress/wp-content/uploads/2017/06/scroll.js\"></script>"
        
        header += "</head>"
        header += "<body>"
        
        //let comment = "<hr id=\"commentAnchor\">" + commentHtml(comments: post.comments)
        
        var footer =  "</body>"
        footer += "</html>"
        
        webView.loadHTMLString(header + post.content!  + footer, baseURL: nil)
    }
    
    
    


    override func viewDidLoad() {
        super.viewDidLoad()
        loadHTML()
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
